package io.plus.user_interface.common.packet;

import io.plus.user_interface.common.Status;
import io.plus.user_interface.common.utils.JsonKit;
import lombok.Data;

import java.io.Serializable;

@Data
public class ResponseMessage implements Serializable {

    private static final long serialVersionUID = 1L;

    private Integer code;//响应状态码;

    private String msg;//响应状态信息提示;

    private Command command;//响应cmd命令码;

    private Object data;//响应数据;

    public ResponseMessage() {
    }

    public ResponseMessage(Command command) {
        this.command = command;
    }

    public ResponseMessage(Command command, Object data) {
        this(command);
        this.data = data;
    }

    public ResponseMessage(Command command, Status status) {
        this(command);
        this.code = status.getCode();
        this.msg = status.getDescription();
    }

    public ResponseMessage(Status status) {
        this.code = status.getCode();
        this.msg = status.getDescription();
    }

    public void clear() {
    }

    public ResponseMessage setCode(Integer code) {
        this.code = code;
        return this;
    }

    public ResponseMessage setCommand(Command command) {
        this.command = command;
        return this;
    }

    public ResponseMessage setData(Object data) {
        this.data = data;
        return this;
    }

    public ResponseMessage setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public byte[] toByte() {
        return JsonKit.toJSONBytesEnumNoUsingName(this);
    }


}
